#include<bits/stdc++.h>
#define int long long 
using namespace std;

const int maxn=1e5+10;
int prefix[maxn];
int suffix[maxn];

int n;

struct Stone{
	int w,p;
	bool operator < (Stone st) const{
		return p<st.p;
	}
};

vector<Stone> stn;
void solve(){
	cin>>n;
	for(int i=1;i<=n;i++){
		int w,p;
		cin>>w>>p;
		stn.push_back({w, p});
	}
	int weight=0;
	sort(stn.begin(), stn.end());
	for(int i=1;i<=n;i++){ // 枚举每堆石头
		prefix[i]=prefix[i-1];
		prefix[i]+=weight*(stn[i-1].p-stn[i-2].p);
		weight+=stn[i-1].w;
	}
	weight=0;
	for(int i=n;i>=1;i--){
		suffix[i]=suffix[i+1];
		suffix[i]+=weight*(stn[i].p-stn[i-1].p);
		weight+=stn[i-1].w;
	}
	int ans=1e18;
	for(int i=1;i<=n;i++){
		ans=min(ans, prefix[i]+suffix[i]);
	}
	cout<<ans<<'\n';
}


signed main(){
	ios::sync_with_stdio(0), cin.tie(0),cout.tie(0);
	solve();
	return 0;
}
